package com.xp.code.daoImpl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.xp.code.dao.ILoginInfoDao;
import com.xp.code.jpa.DefaultJPADAO;

@Repository("loginInfoDao")
public class LoginInfoDao extends DefaultJPADAO implements ILoginInfoDao {

	
	public List<Object[]> validateLogin(String username,String passwd){
		Query query=this.getEntityManager().createNativeQuery("SELECT T1.ID,T1.VARNAME,T1.PASSWORD,T1.USERNAME,CASE WHEN T1.VALIDDATE>SYSDATE then 0 else 1 end VALIDDATES,T1.VALIDFLAG,T3.ID DEPTID,T3.VARNAME DEPTNAME,T5.ID UNITID,T5.VARNAME UNITNAME FROM TSYS_USER T1 LEFT JOIN TSYS_USER_DEPARTMENT T2 ON T1.ID=T2.USERID LEFT JOIN TSYS_DEPARTMENT T3 ON T2.DEPTID=T3.ID LEFT JOIN TSYS_DEPT_UNIT T4 ON T3.ID=T4.DEPTID LEFT JOIN TSYS_UNIT T5 ON T4.UNITID=T5.ID WHERE T1.VARNAME=:VARNAME");
		query.setParameter("VARNAME", username);
		List<Object[]> list=query.getResultList();
		return list;
	}
}
